﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using SwenAssigment.Classes;
namespace SwenAssigment
{
    public partial class RoomUpdate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string sss = (string)Session["rarid"];
            if (sss != null)
            {
                if (Label1.Text == "Label")
                {
                    string line = "select * from room where Room_ID='" + sss + "'";
                    RADcon con = new RADcon();
                    string[] s = con.raretrieveone(line);
                    Label1.Text = s[0];
                    Label2.Text = s[1];
                    Label3.Text = s[2];
                    TextBox1.Text = s[3];
                    Session["rarid"] = "";
                    if (Page.Request.UrlReferrer.LocalPath == "/RoomDetail.aspx")
                    {

                    }
                    else
                    {
                        Response.Redirect("RoomAvalibility.aspx");
                    }
                }
            }
            else
            {
                Response.Redirect("RoomAvalibility.aspx");
            }
        }

        protected void raupdate_Click(object sender, EventArgs e)
        {
            try
            {
                RADcon con = new RADcon();
                int id = int.Parse(Label1.Text);
                decimal cost = decimal.Parse(TextBox1.Text);
                string stat = "";
                if (DropDownList2.Text == "Vacant - To be cleaned")
                {
                    stat = "Clean";
                }
                else if (DropDownList2.Text == "Room service")
                {
                    stat = "Service";
                }
                else
                {
                    stat = DropDownList2.Text;
                }
                bool b = con.raupdate(id, cost, stat);
                if (b == true)
                {
                    Session["mystat"] = "Room Updated";
                    Response.Redirect("RoomAvalibility.aspx");
                }
                else
                {
                    Label4.Visible = true;
                }
            }
            catch
            {
                Label4.Visible = true;
            }
        }
    }
}